package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Dept;
import com.qf.bean.Major;
import com.qf.bean.User;
import com.qf.mapper.DeptMapper;
import com.qf.mapper.MajorMapper;
import com.qf.mapper.UserMapper;
import com.qf.service.UserService;
import com.qf.vo.ResultVo;
import com.qf.vo.UserAllVo;
import com.qf.vo.UserDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.*;

@Service
public class UserServiceImpl implements UserService {
   @Resource
   private UserMapper userMapper;
    @Resource
   private DeptMapper deptMapper;
    @Resource
private MajorMapper majorMapper;



    @Override
    public int insert(User user) {
        return  userMapper.insert(user) ;
    }

    @Override
    public User findBy(String realname) {
        return userMapper.findBy(realname);
    }



    @Override
    public UserDetailVo finBy(String realname) {
        return userMapper.finDetail(realname);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }
//修改密码
    @Override
    public int updatE(User user) {
        return userMapper.upda(user);
    }

    @Override
    public PageInfo<UserAllVo> findUserAll(int index, int size, String deptname, String realname) {
        //制定分页参数
        PageHelper.startPage(index,size);
        //封装查询条件
        HashMap map=new HashMap();
        map.put("deptname",deptname);
        map.put("realname",realname);
       List<UserAllVo> userAllVos=userMapper.find(map);
       //封装到PageInfo中b
        PageInfo<UserAllVo> pageInfo=new PageInfo<UserAllVo>(userAllVos);
        return pageInfo;
    }

    @Override
    public User findByUsername(String username) {
        return userMapper.findByusername(username);
    }

    @Override
    public Set<String> findRoleNamesByUsername(String username) {

        return userMapper.findRoleNameByUsername(username);
    }

    @Override
    public Set<String> findPermissionsByRoleNames(Set<String> roleNames) {
        //封装参数
        Map<String,Object> map=new HashMap<>();
        map.put("set",roleNames);
        //查询并且返回
       return userMapper.findPermissionByroNames(map);



    }

    @Override
    public LinkedHashMap<String, String> findFilterChainDefinition() {
        return  userMapper.findFilterChainDefinition();
    }

    @Override
    public int del(String realname) {
        return userMapper.del(realname);
    }
//在有增添图片信息的时候可以用通用mapper
    @Override
    public int save(User user) {
        return userMapper.insertSelective(user);
    }

    @Override
    public List<UserAllVo> findByids(int[] userid) {
        return userMapper.findByids(userid);
    }

    @Override
    public List<Integer> findNotActiveDevUserOverThreeDays() {
        return userMapper.findOverThreeDayNotState();
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
  //利用通用mapper
        Example example=new Example(User.class);
        //封装删除条件
        Example.Criteria criteria= example.createCriteria();
        criteria.andIn("userid",ids);
        //执行删除
        userMapper.deleteByExample(example);
    }

    @Override
    public int updateqianBy(String username, int money) {
        return userMapper.updateMoneyByUsername(username,money);
    }
    //充值金额符合要求就要修改角色信息
    @Override
    public int updaterolenaemBy(String username) {
        return userMapper.updateRolenameBy(username);

    }
//修改账户历史的钱


}
